package com.yellowpage.omc.datacollect.service;

import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import com.yellowpage.omc.datacollect.data.DataCollect;
import com.yellowpage.omc.datacollect.data.DataCollectBatch;
import com.yellowpage.white.dao.QueryAssistantSQL;

public class DataCollectImportTask extends Thread {
	List dataCollectList;
	DataCollectBatch dataCollectBatch;
	private DataCollectBatchService dataCollectBatchService;
	private DataCollectService dataCollectService;

	public DataCollectImportTask(List dataCollectList,
			DataCollectBatch dataCollectBatch,
			DataCollectBatchService dataCollectBatchService,
			DataCollectService dataCollectService) {

		this.dataCollectList = dataCollectList;
		this.dataCollectBatch = dataCollectBatch;
		this.dataCollectBatchService = dataCollectBatchService;
		this.dataCollectService = dataCollectService;

	}

	public void run() {

		long dataCount = 0;
		int currentRow = 0;
		int currentCol = 0;

		DataCollect dataCollect = null;
		
		

		try {
			// 遍历每个Sheet
			for (int s = 0; s < dataCollectList.size(); s++) {
				dataCollect = (DataCollect) dataCollectList.get(s);
				
				dataCollectService.initDataCollectRegion(dataCollect);						
								
				List dataCollectList = dataCollectBatchService.processImportDataCollect(dataCollect);
				
				for(int i = 0; i < dataCollectList.size(); i++){
					dataCollectService.saveDataCollect((DataCollect)dataCollectList.get(i));
				}				
				
			}

			dataCollectBatch.setStatus("COMPLETED");
			dataCollectBatchService.updateDataCollectBatch(dataCollectBatch);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
